{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1月2号课程的准备\n",
    "## 字符串的一些函数  [strip] [split] [id] [len]\n",
    "## 遍历字符串,遍历列表\n",
    "## 实现模糊搜索和多字段搜索,结合003的最后实现\n",
    "## if 数据的控制\n",
    "## 字典的迭代器使用 [] [] 熟练掌握\n",
    "## dir 函数的使用 # 用来看相关模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "不存在\n"
     ]
    }
   ],
   "source": [
    "# 让他支持 7125,7126,7127, 都给我返回\n",
    "# 让他支持模糊查询  71 苹果 香蕉 橘子 27 橘子和雪龙国\n",
    "trans_code  ={\"7125\":\"苹果\",\"7126\":\"香蕉\",\"7127\":\"橘子\",\"6127\":\"雪龙果\"}\n",
    "value = input(\"请输入你需要查询的code: \")\n",
    "\n",
    "if value in trans_code:\n",
    "    print(trans_code[value])\n",
    "    \n",
    "else:  \n",
    "    trans_code[value]='不存在'\n",
    "    print(trans_code[value])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "字符串里面的元素 I\n",
      "字符串里面的元素 a\n",
      "字符串里面的元素 m\n",
      "字符串里面的元素 c\n",
      "字符串里面的元素 h\n",
      "字符串里面的元素 i\n",
      "字符串里面的元素 n\n",
      "字符串里面的元素 a\n",
      "1\n",
      "2\n",
      "3\n",
      "列表里面的元素:  1\n",
      "列表里面的元素:  2\n",
      "列表里面的元素:  3\n",
      "列表里面的元素:  4\n"
     ]
    }
   ],
   "source": [
    "## 遍历字符串,遍历列表\n",
    "#for statement in val:\n",
    "apple =\"Iamchina\"\n",
    "list1 = [1,2,3,4]\n",
    "trans_code  ={\"7125\":\"苹果\",\"7126\":\"香蕉\",\"7127\":\"橘子\",\"6127\":\"雪龙果\"}\n",
    "\n",
    "#dict.value , dict.keys() \n",
    "for i in apple:\n",
    "    #apple =\"Iamchina\"\n",
    "    print(\"字符串里面的元素\",i)\n",
    "\n",
    "print(list1[0])\n",
    "print(list1[1])\n",
    "print(list1[2])\n",
    "for i in list1:\n",
    "    print(\"列表里面的元素: \",i)\n",
    "\n",
    "# for i in trans_code:\n",
    "#     print(\"字典里面的元素: \",i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'dict'>\n",
      "7125 苹果\n",
      "7126 香蕉\n",
      "7127 橘子\n",
      "6127 雪龙果\n",
      "字典里面值: 苹果\n",
      "字典里面值: 香蕉\n",
      "字典里面值: 橘子\n",
      "字典里面值: 雪龙果\n"
     ]
    }
   ],
   "source": [
    "trans_code  ={\"7125\":\"苹果\",\"7126\":\"香蕉\",\"7127\":\"橘子\",\"6127\":\"雪龙果\"}\n",
    "print(type(trans_code))\n",
    "#dict.value , dict.keys() \n",
    "#print(trans_code.values)\n",
    "#print(trans_code.keys)\n",
    "# trans_code.items():\n",
    "for key,value in trans_code.items():\n",
    "    print(key,value)\n",
    "\n",
    "for i in trans_code:\n",
    "    #print(\"字典里面的元素: \",i)\n",
    "    print(\"字典里面值:\",trans_code[i])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7125 苹果\n",
      "7126 香蕉\n",
      "7127 橘子\n",
      "6127 雪龙果\n"
     ]
    }
   ],
   "source": [
    "trans_code  ={\"7125\":\"苹果\",\"7126\":\"香蕉\",\"7127\":\"橘子\",\"6127\":\"雪龙果\"}\n",
    "search_code = input(\"请输入你需要查询的code: \")\n",
    "for key,value in trans_code.items():\n",
    "\n",
    "    #key 7125 7126\n",
    "    #value 苹果,香蕉\n",
    "    if search_code in key or search_code in value: #存在我走下面\n",
    "\n",
    "        print(key,value)\n",
    "    else:\n",
    "        print(\"我在第二行\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我不存在\n",
      "我存在\n",
      "我存在\n",
      "我不存在\n"
     ]
    }
   ],
   "source": [
    "# 字符串 元组  字典 列表 数据类型 \n",
    "#if  空的 为None 就是假,其他都是真\n",
    "\n",
    "# 字符串除了空值 或None都是都是true,空格也是true\n",
    "apple = ''\n",
    "\n",
    "if apple: #存在为真\n",
    "    print(\"我存在\")\n",
    "else:\n",
    "    print(\"我不存在\")\n",
    "apple = '1'\n",
    "if apple: #存在为真\n",
    "    print(\"我存在\")\n",
    "else:\n",
    "    print(\"我不存在\")\n",
    "apple = ' '\n",
    "if apple: #存在为真\n",
    "    print(\"我存在\")\n",
    "else:\n",
    "    print(\"我不存在\")\n",
    "apple =None\n",
    "if apple: #存在为真\n",
    "    print(\"我存在\")\n",
    "else:\n",
    "    print(\"我不存在\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "#字典 列表\n",
    "\n",
    "t = ['1','2','3']\n",
    "ts = []\n",
    "if t:\n",
    "    print(True)\n",
    "else:\n",
    "    print(False)\n",
    "\n",
    "if ts:\n",
    "    print(True)\n",
    "else:\n",
    "    print(False)\n",
    "\n",
    "\n",
    "dict_ceshi = {}\n",
    "if dict_ceshi:\n",
    "    print(True)\n",
    "else:\n",
    "    print(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "a = 2\n",
    "if a==1:\n",
    "    print(1)\n",
    "elif(a==2):\n",
    "    print(2)\n",
    "else:\n",
    "    print(3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "ceshi_turple = () \n",
    "if ceshi_turple:\n",
    "    print(True)\n",
    "else:\n",
    "    print(False)\n",
    "ceshi_turple = (1,2)\n",
    "if ceshi_turple:\n",
    "    print(True)\n",
    "else:\n",
    "    print(False)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "trans_code  ={\"7125\":\"苹果\",\"7126\":\"香蕉\",\"7127\":\"橘子\",\"6127\":\"雪龙果\"}\n",
    "search_code = input(\"请输入你需要查询的code: \")\n",
    "for key,value in trans_code.items():\n",
    "\n",
    "    #key 7125 7126\n",
    "    #value 苹果,香蕉\n",
    "    if search_code in key or search_code in value: #存在我走下面\n",
    "\n",
    "        print(key,value)\n",
    "    else:\n",
    "        print(\"我在第二行\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']\n",
      "I amxiaoxusheng\n",
      "I amxiaoxusheng\n",
      "<built-in method count of str object at 0x0000012E501EC630>\n",
      "4\n",
      "Help on built-in function replace:\n",
      "\n",
      "replace(old, new, count=-1, /) method of builtins.str instance\n",
      "    Return a copy with all occurrences of substring old replaced by new.\n",
      "    \n",
      "      count\n",
      "        Maximum number of occurrences to replace.\n",
      "        -1 (the default value) means replace all occurrences.\n",
      "    \n",
      "    If the optional argument count is given, only the first count occurrences are\n",
      "    replaced.\n",
      "\n",
      "None\n",
      "daxuesheng\n"
     ]
    }
   ],
   "source": [
    "apple = \"I am\"\n",
    "if 'I' in apple: #存在为真\n",
    "    print(True)\n",
    "else:\n",
    "    print(False) #不存在为假\n",
    "\n",
    "    # 1月2号课程的准备\n",
    "\n",
    "\n",
    "print(dir(apple))  #replace  join  split  #stri\n",
    "student = \"xiaoxusheng\"\n",
    "AppleStudent = apple+student\n",
    "print(AppleStudent)\n",
    "t=apple.__add__(student)\n",
    "print(t)\n",
    "#print(count(apple))\n",
    "print(apple.count)\n",
    "print(len(apple))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "daxuesheng\n",
      "xiaoxusheng\n"
     ]
    }
   ],
   "source": [
    "student = \"xiaoxusheng\"\n",
    "\n",
    "#print(help(student.replace))\n",
    "stu = student.replace(\"xiaoxusheng\",\"daxuesheng\") #find repalce\n",
    "print(stu)\n",
    "print(student)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据不符合条件 1\n",
      "数据不符合条件 2\n",
      "[3, 4]\n",
      "<class 'list'>\n",
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n",
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n"
     ]
    }
   ],
   "source": [
    "## 字符串的一些函数  [strip] [split] [id] [len]\n",
    "## 字典的迭代器使用 [] [] 熟练掌握\n",
    "\n",
    "apple = [1,2,3,4]\n",
    "new_apples= []\n",
    "\n",
    "#print(dir(new_apples))\n",
    "#print(help(new_apples.append))\n",
    "for i in apple: #for循环\n",
    "    if i >2: #if 区间判断\n",
    "        new_apples.append(i)\n",
    "    else:\n",
    "        print(\"数据不符合条件\",i)\n",
    "        continue\n",
    "\n",
    "\n",
    "print(new_apples)\n",
    "ceshi_apple = [i for i in apple if i>3]\n",
    "ceshi_apple =[] \n",
    "for i in apple:\n",
    "    if i>3:\n",
    "        ceshi_apple.append(i)\n",
    "apple_list = [x for x in range(20)]  # [] append  符合条件的所有的值一个一个追加到列表里面\n",
    "print(type(apple_list))\n",
    "print(apple_list)\n",
    "apple_list = [] \n",
    "for x in range(20):\n",
    "    apple_list.append(x) \n",
    "print(apple_list)\n",
    "# print(\"迭代器语法: \",ceshi_apple)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "trans_code  ={\"7125\":\"苹果\",\"7126\":\"香蕉\",\"7127\":\"橘子\",\"6127\":\"雪龙果\"}\n",
    "search_code = input(\"请输入你需要查询的code: \")\n",
    "\n",
    "# 改成一个迭代器 那种 [] \n",
    "for key,value in trans_code.items():\n",
    "\n",
    "    #key 7125 7126\n",
    "    #value 苹果,香蕉\n",
    "    if search_code in key or search_code in value: #存在我走下面\n",
    "\n",
    "        print(key,value)\n",
    "    else:\n",
    "        print(\"我在第二行\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "循环字典 .循环列表,循环元组,循环字符串.\n",
    "字符出那些方法 \n",
    "熟练掌握dir函数 help函数\n",
    "列表里面的append函数,\n",
    "迭代器 app = [x for x in range(20)]\n",
    "if 判断  字符串，列表，字典，元组 掌握什么是真，什么是假,"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "放到两个文件里面  我要查询的数据search_keyword.txt[我拿的匹配的列] , hailiang.txt 【excle 里面对应的A列】 #我输入的列需要在hailiang.txt这里面存在。我需要迅速筛选出来,并标记存不存在\n",
    "\n",
    "## 100个字典去查询 被查500条 \n",
    "# open 7123 7125 我要查100 个1000个 \n",
    "vscode \n",
    "pycharm  linux 的环境配置，和编写"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.11.5 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  },
  "vscode": {
   "interpreter": {
    "hash": "c261aea317cc0286b3b3261fbba9abdec21eaa57589985bb7a274bf54d6cc0a7"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
